//该文件用于创建Vuex中最为核心的store

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

//用于响应组件的动作
const actions = {
    jiaOdd(miniStore, value) {
        console.log('actions中的jiaOdd被调用了', miniStore, value);
        if (miniStore.state.sum % 2) {
            miniStore.commit('JIA', value)
        }
    },
    jiaWait(miniStore, value) {
        setTimeout(() => {
            miniStore.commit('JIA', value)
        }, 800);
    },
}

//用于操作数据
const mutations = {
    JIA(state, value) {
        console.log('mutations中的jia被调用了', state, value);
        state.sum += value
    },
    JIAN(state, value) {
        state.sum -= value
    },

}

//用于存储数据
const state = {
    sum: 0, //当前求和
    school: '尚硅谷',
    subject: '前端'
}

//用于加工数据
const getters = {
    bigSum(state) {
        return state.sum * 10
    }
}

//创建并暴露store 
export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})